<template>
  <div>
    <div class="data">
    <p>用户名</p><el-input type="text" name="" id="" v-model="name" :placeholder="author.username"/>
    <p>密码</p><el-input type="password" name="" id="" v-model="password" />
    <p>邮箱</p><el-input type="text" name="" id="" v-model="email"  :placeholder="author.email"/>
    </div>
    <el-button @click="change">确定更改</el-button>
    <el-button @click="cancle">取消</el-button>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            name:'',
            password:'',
            email:'',
            author:this.$store.state.user,
            oldname:this.$store.state.user.username
        }
    },
    methods:{
        change(){
            axios.post('/updateUser',{
                username:this.name,
                password:this.password,
                email:this.email,
                oldname:this.oldname
            }).then(res=>{
                console.log(res);
                const user = {
                username:this.name,
                password:this.password,
                email:this.email,
                }
                this.$store.commit('putUser',user)
                 this.name='',
            this.password='',
            this.email='',
            this.$message('修改成功！');
            }).catch(error=>{
                console.log(error);
            })
        },
        cancle(){
            this.name='',
            this.password='',
            this.email=''
        }
    }
}
</script>

<style>

</style>